README - Replication Code for "Externalities of Policy-Induced Scrappage: The Case of Automotive Regulations" by Connor R. Forsythe, Akshaya Jha, Jeremy J. Michalek, and Kate S. Whitefoot

*****Directory Structure*****

This folder contains the necessary data and code to recreate all primary results contained in "Externalities of Policy-Induced Scrappage: The Case of Automotive Regulations". There is one primary directories which are described below along with descriptions of the contents in each sub-directory. Note, running the full code on a 14" 2021 MacBook Pro with 32 GB of RAM takes roughly 7 hours. Leave-one-out analyses and random treatment analyses often take the most time. For much faster results, comments these sections out of the "RunModel.do" file.


- Primary Model
	--CleanedData; Data used to estimate primary model and various sensitivity cases.
		---EmissionsProgramsV2.xlsx; Data recording emission inspection program start and end years for all states. URLs where the information was collected are recorded in workbook.
		---UrbanRuralVMT.csv; Urban and Rural VMT levels. These data come from the same VMT sources listed in Table 1.
		---FHWACleanV4.csv; All FHWA data outlined in Table 1 for primary analysis.
		---FHWACleanV4.csv; All FHWA data outlined in Table 1 for primary analysis.
	--Data; Data saved in this directory during the process of running model. Used to save Bacon Decomposition results.
	--Logs; Stata logs saved to this directory.
	--Plots; Plots saved to this directory.
		---LOO; Plots describing leave-one-out analyses saved here.
		---NeighborAnalysis; Plots describing spillover analysis (i.e. treatment impact on neighboring states) saved here.
		---RandTreatSim; Plots describing random treatment simulation analysis saved here.
		---ResidualPlots; Plots of residuals saved here.
	--PythonScripts; Scripts called by Stata during analysis are stored here.
		---Data; Various intermediate data necessary for result estimation/calculation.
		---Plots
			----Elasticities; Plots of elasticity comparison saved here.
			----Externalities; Plots of externality comparison saved here.
		---Tables
			----externalities.xlsx; stored externality data
		---plotResiduals.py;
		---plotExternalities.py;
		---PlotElasticityComparisons.py;
		---outputLOO.py;
		---Inflator.py;
		---combineIV.py;
		---calculateExternalities.py;
		---calculateARStat.py;
		---addNeighboringStateVariables.py;
	--Tables; Tables are saved to this directory.
		---iv.xlsx; Final results from all IV analyses are stored in this file. Separate files are created for each specification and combined into this one file.
		---Elasticities; Tables of elasticity comparison saved here.
		---LOO; Tables describing leave-one-out analyses saved here.
		---NeighborAnalysis; Tables describing spillover analysis (i.e. treatment impact on neighboring states) saved here.
		----Externalities; Folder where several tables are stored
		---RandTreatSim; Tables describing random treatment simulation analysis saved here.
	--bacondecomp2.do; A slightly edited version of the bacondecomp package (available at https://ideas.repec.org/c/boc/bocode/s458676.html) that corrects a small bug in the current version of the code. Reproduced with the permission of the corresponding author Austin Nichols.
	--BaconEstimation.do; Estimates Bacon Decomposition.
	--externalityAnalysis.do; Performs externality analysis comparisons.
	--GasUseIV.do; Estimates gas use outcome IV models.
	--GasUseIVIVEmissions.do; Estimates the gas use outcome IV model controlling for emissions programs.
	--GasUseIVLOO.do; Runs leave one out analysis for gas use IV models under primary specification.
	--GasUseRFDiD.do; Estimated reduced form models with gas use outcomes.
	--GasUseRFES.do; Estimate event study models with gas use outcomes.
	--LoadDataBacon.do; Loads and clean data utilized in Bacon Decomposition. Ensures for a balanced panel.
	--LoadDataGasUse.do; Loads and cleans data utilized in gas use analyses.
	--LoadDataVMT.do; Loads and cleans data utilized in travel analyses.
	--neighborStateAnalysis.do; Estimates spillover analyses with registration outcomes.
	--LOO.do; Runs leave one out analysis for the registration difference in differences under the primary specification.
	--neighborStateAnalysisGasUse.do; Estimates spillover analyses with gas use outcomes.
	--neighborStateAnalysisVMT.do; Estimates spillover analyses with travel outcomes.
	--programs.do; Contains various programs used for model estimation and storing results.
	--RandTreatSimReg.do; Randomly simulates treatment and estimates difference in differences models.
	--RegDiD.do; Estimates registration difference in differences models.
	--RegDiDMetro.do; Estimates DiD model with policy interaction with pre-treatment metro population share.
	--RegDIDEmissions.do; Estimates DiD model with emissions programs controls.
	--RegES.do; Estimates registration event studies.
	--RegESWoTT.do; Estimates registration event studies without the inclusion of state-specific time trends.
	--RunModel.do; Primary script that should be used to run full analysis. Running individual scripts may not work properly as there are data/program dependencies handled across scripts. Best practice is to run sections of this script if one would like to recreate specific results.
	--ReviewResponse.do; An additional script to run the additional Urban/Rural and emissions-inspection-controlling analyses contained in the SI.
	--summarizeLOO.do; Creates the summary information for the leave one out analyses.
	--SummarizeRandTreatment.do; Summarizes the output from randomized treatment exercise.
	--VMTIV.do; Estimates both the travel outcome IV models presented in the paper.
	--VMTIVEmissions.do; Estimates the travel outcome IV model controlling for emissions programs.
	--VMTIVLOO.do; Runs leave one out analysis for the travel IV model under the primary specification.
	--VMTIVUrbanRural.do; Estimates VMT IV across urban/rural travel outcomes.
	--VMTRFRuralUrban.do; Estimates reduced form model for urban/rural travel outcomes.
	--VMTRFDiD.do; Estimates reduced form model for travel outcomes.
	--VMTRFES.do; Estimates event study for travel outcomes.
	--TwowayHistGasUse.m; Creates data availability plots for gas use outcomes for figures A.1 and A.2
	--TwowayHistVMT.m; Creates data availability plots for VMT outcomes for figures A.1 and A.2

- NHTSAnalysis
	--CleanData
		--- FullNHTS2017.csv; 2017 National Household Travel Survey Data (cited in text).
		--- FullNHTS2017.csv; 2009 National Household Travel Survey Data (cited in text).
	--Tables
		--- NHTS.tex; Results from the auxillary NHTS cross-sectional analysis.
	--AnalyzeSingleMultiVehicleDriving.py; creates VMT/vehicle comparison plot shown in Figure 
	--CausalNHTS.do; runs auxillary NHTS cross-sectional analysis.
- Maps
	--Plots; This directory stores the maps for Figure 2
	--cb_2018_us_state_500k 2; This directory stores the plotting data cited in the text.
	--FHWACleanV4.csv; All FHWA data outlined in Table 1 for primary analysis.
	--plotTreatmentInfoMaps.py; Script to build map for Figure 2



*****Main Body Plot and Table Locations*****
-Tables
	-- Table 3: Subset of columns in table located at PrimaryModel/Tables/DiD/RegDiD. This is generated in PrimaryModel/RegDiD.do.
	-- Table 4: Subset of columns in table located at PrimaryModel/Tables/IV/VMTiv. This is generated in PrimaryModel/VMTIV.do.
	-- Table 5: Subset of columns in table located at PrimaryModel/Tables/IV/GasUseiv. This is generated in PrimaryModel/GasUseIV.do.
	-- Table C.2: PrimaryModel/Tables/DiD/RegDiD. This is generated in PrimaryModel/RegDiD.do.
	-- Table C.3: PrimaryModel/Tables/IV/VMTiv. This is generated in PrimaryModel/VMTIV.do.
	-- Table C.4: PrimaryModel/Tables/IV/GasUseiv. This is generated in PrimaryModel/GasUseIV.do.
	-- Table C.5: PrimaryModel/Tables/DiD/RegDiDWoTT. This is generated in PrimaryModel/RegDiD.do.
	-- Table C.6: PrimaryModel/Tables/LOO/LOO-VMT. This is generated in PrimaryModel/VMTIVLOO.do
	-- Table C.7: PrimaryModel/Tables/LOO/LOO-Gas. This is generated in PrimaryModel/GasUseIVLOO.do
	-- Table C.8: PrimaryModel/Tables/LOO/LOO-DiDPValues.  This is generated in PrimaryModel/PythonScripts/outputLOO.py.
	-- Table C.9: PrimaryModel/Tables/DiD/RegPerCapitaDiD. This is generated in PrimaryModel/RegDiD.do.
	-- Table C.10: PrimaryModel/Tables/IV/VMTPerCapitaiv. This is generated in PrimaryModel/VMTIV.do.
	-- Table C.11: PrimaryModel/Tables/IV/GasUsePerCapitaiv. This is generated in PrimaryModel/GasUseIV.do.
	-- Table C.12: PrimaryModel/Tables/RandTreatSim/RandTreatRejectionRates. This is generated in PrimaryModel/RandTreatSimReg.do.
	-- Table E.1: NHTSAnalysis/Tables/NHTS.tex.  This is generated in NHTSAnalysis/CausalNHTS.do.
	-- Table F.1: PrimaryModel/ReviewResponseResults/RegDiDEmissions.tex. This is generated from PrimaryModel/ReviewResponse.do.
	-- Table F.2: Information in this table is identified in Table 4 and the workbook PrimaryModel/Tables/iv-Spec2Emissions.xlsx. This is generated from PrimaryModel/ReviewResponse.do.
	-- Table F.3: Information in this table is identified in Table 5 and the workbook PrimaryModel/Tables/iv-Spec2GasUseEmissions.xlsx. This is generated from PrimaryModel/ReviewResponse.do.
	-- Table G.1: Information in this table is identified in the output from PrimaryModel/RegDiDMetro.do. This can be found in PrimaryModel/ReviewResponseResults/ReviewResponse.pdf. This is generated from PrimaryModel/ReviewResponse.do.
	-- Table G.2: Information in this table is identified in the output from PrimaryModel/VMTRFRuralUrban.do. This can be found in PrimaryModel/ReviewResponseResults/ReviewResponse.pdf. This is generated from PrimaryModel/ReviewResponse.do.
-Figures
	-- Figure 2: Maps/Plots/Cont48InspectionBounds.pdf. This is generated in Maps/plotTreatmentInfoMaps.py.
	-- Figure 4: PrimaryModel/Plots/ES/RegESSpec26.png. This is generated in PrimaryModel/RegES.do.
	-- Figure 5: PrimaryModel/Plots/NeighborAnalysis/NeighborStateSpec26.png.  This is generated in PrimaryModel/neighborStateAnalysis.do.
	-- Figure C.1: PrimaryModel/PlotsResidualPlots/Spec1ResPlot.png; PrimaryModel/PlotsResidualPlots/Spec2ResPlot.png; PrimaryModel/PlotsResidualPlots/Spec3ResPlot.png; PrimaryModel/PlotsResidualPlots/Spec4ResPlot.png.  This is generated in PrimaryModel/PythonScripts/plotResiduals.py.
	-- Figure C.2: PrimaryModel/Plots/ES/RegESSpec16.png; PrimaryModel/Plots/ES/RegESSpec26.png; PrimaryModel/Plots/ES/RegESSpec36.png; PrimaryModel/Plots/ES/RegESSpec46.png.  This is generated in PrimaryModel/RegES.do.
	-- Figure C.3: PrimaryModel/Plots/ES/RegESSpec111.png; PrimaryModel/Plots/ES/RegESSpec211.png; PrimaryModel/Plots/ES/RegESSpec311.png; PrimaryModel/Plots/ES/RegESSpec411.png.  This is generated in PrimaryModel/RegES.do.
	-- Figure C.4: PrimaryModel/Plots/ES/RegESSpec1WoTT6.png; PrimaryModel/Plots/ES/RegESSpec2WoTT6.png; PrimaryModel/Plots/ES/RegESSpec3WoTT6.png; PrimaryModel/Plots/ES/RegESSpec4WoTT6.png.  This is generated in PrimaryModel/RegESWoTT.do.
	-- Figure C.5: PrimaryModel/Plots/ES/RegESSpec1WoTT11.png; PrimaryModel/Plots/ES/RegESSpec2WoTT11.png; PrimaryModel/Plots/ES/RegESSpec3WoTT11.png; PrimaryModel/Plots/ES/RegESSpec4WoTT11.png.  This is generated in PrimaryModel/RegESWoTT.do.
	-- Figure C.6: PrimaryModel/Plots/LOO/ivHistogram.png; This is generated in PrimaryModel/summarizeLOO.do.
	-- Figure C.7: PrimaryModel/Plots/LOO/didHistogram.png; This is generated in PrimaryModel/summarizeLOO.do.
	-- Figure C.8: PrimaryModel/Plots/NeighborAnalysis/NeighborStateJointSpec26.png; This is generated in PrimaryModel/neighborStateAnalysis.do.
	-- Figure C.9: PrimaryModel/PlotsES/RegESSpec2PerCapita11.png; This is generated in PrimaryModel/RegES.do.
	-- Figure C.10: PrimaryModel/Plots/RandTreatSim/RandTreatRegTreatedStatesCombined.png; This is generated in PrimaryModel/SummarizeRandTreatment.do.
	-- Figure C.11: PrimaryModel/Plots/RandTreatSim/RandTreatRegAllStatesCombined.png; This is generated in PrimaryModel/SummarizeRandTreatment.do.
	-- Figure C.12: PrimaryModel/Plots/Bacon/bacReg.png; PrimaryModel/Plots/Bacon/bacVMT.png; PrimaryModel/Plots/Bacon/bacGas.png; This is generated in PrimaryModel/BaconEstimation.do.  
	-- Figure C.13: PrimaryModel/Plots/Bacon/bacRegOverTime.png; PrimaryModel/Plots/Bacon/bacVMTOverTime.png; PrimaryModel/Plots/Bacon/bacGasOverTime.png; This is generated in PrimaryModel/BaconEstimation.do. 
	-- Figure E.1: ResponsePlots/travel_per_vehicle_2009.png; ResponsePlots/travel_per_vehicle_2017.png; This is generated in NHTSAnalysis/AnalyzeSingleMultiVehicleDriving.py.
	-- Figure H.1: Plots/Externalities/TotalExternalitiesV4.png. This is generated in PrimaryModel/PythonScripts/plotExternalities.py.


*****Tables and Figures Produced with Propietary Data from Pennsylvania's e-Safety program*****
-Tables
	-- Table 2
-Figures
	-- Figure 3

*****Software Requirements*****
The Stata codes leverages a relatively new feature that enables Stata to call Python scripts directly within Stata .do files. Therefore, one must properly set up their Python settings within Stata as well as ensure the referenced Python executable has access to the required packages (listed below).

***Stata Package Requirements***
-Stata 17
-reghdfe; version 5.7.3 13nov2019; Documentation available at http://scorreia.com/software/reghdfe/
-bacondecomp; 1.0.5 16sep2022: Documentation available at https://ideas.repec.org/c/boc/bocode/s458676.html
-coefplot;  version 1.8.5  23nov2021: Documentation available at http://repec.sowi.unibe.ch/stata/coefplot/getting-started.html
-estout; version 3.30  25mar2022; Documentation available at http://repec.sowi.unibe.ch/stata/estout/

***Python Package Requirements***
-Primary Model Scripts
	--python; 3.8.13
	--numpy; 1.21.5
	--scipy; 1.7.3
	--matplotlib; 3.5.1
	--pandas; 1.4.3
	--seaborn; 0.11.2
	--xlxswriter; 3.0.3
-NHTSAnalysis Scripts
	--python; 3.11.8
	--numpy; 1.26.4
	--matplotlib; 3.8.0
	--pandas; 2.1.4
	--seaborn; 0.13.2
	--tqdm; 4.66.2
-Maps
	--python 3.8.13
	--matplotlib 3.7.2
	--geopandas; 0.11.1
	--numpy; 1.23.1
	--pandas; 1.2.5